package com.cw.lang.validator.config;

import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;

/**
 * validator校验器拦截定义，把所有被Spring管理的方法，都做校验
 *
 * @author chenw
 * @version $$Id: AllMethodValidationPostProcessor.java, v 0.1 2018/9/20 上午11:13 chenw Exp $$
 */
public class AllMethodValidationPostProcessor extends MethodValidationPostProcessor {

    /** serialVersionUID */
    private static final long serialVersionUID = -6862396896432780032L;

    @Override
    public void afterPropertiesSet() {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        // 针对于所有被Spring管理的方法，除了base中的
        pointcut.setExpression("within(com.cw..*) && !within(com.cw.base..*)");
        this.advisor = new DefaultPointcutAdvisor(pointcut, createMethodValidationAdvice(null));
    }
}
